<MudFileUpload @ref="@_fileUpload"
               T="IReadOnlyList<IBrowserFile>"
               AppendMultipleFiles="AppendMultipleFiles"
               @bind-Files="Files"
               @bind-Files:after="@OnFilesChangedAsync">
    <ActivatorContent>
        <MudButton>
            Open file picker
        </MudButton>
    </ActivatorContent>
</MudFileUpload>

<MudButton OnClick="@ClearAsync">
    Clear
</MudButton>

@code {
    private MudFileUpload<IReadOnlyList<IBrowserFile>> _fileUpload = null!;

    [Parameter]
    public bool AppendMultipleFiles { get; set; } = true;

    public IReadOnlyList<IBrowserFile>? Files { get; private set; } = [];

    private async Task OnFilesChangedAsync()
    {
        // reading files with every change should not throw errors in the console
        foreach (var file in Files ?? [])
        {
            var content = new byte[file.Size];
            _ = await file.OpenReadStream(long.MaxValue).ReadAsync(content);
        }
    }

    private Task ClearAsync() => _fileUpload.ClearAsync();
}